﻿@inherits BasePage
@attribute [Page(NoBreadcrumb = true)]

<GridRow>
    <GridCol Span="24">
        <div class="ws-space">
            <div class="ws-welcome">
                <img class="ws-avatar" src="@user?.AvatarUrl" />
                <div class="ws-info">
                    <span class="ws-name">@info?.Greeting</span>
                    <span class="ws-tips">今天是：@DateTime.Now.ToString("yyyy年MM月dd日 dddd")</span>
                </div>
            </div>
            <ul class="count">
                <li>
                    <span class="name">用户数量<span class="month">总</span></span>
                    <span class="amount">@info?.Statistics?.UserCount</span>
                </li>
                <li>
                    <span class="name">日志数量<span class="month">总</span></span>
                    <span class="amount">@info?.Statistics?.LogCount</span>
                </li>
            </ul>
        </div>
    </GridCol>
</GridRow>
<GridRow>
    <GridCol Span="14">
        <div style="height:400px;">
            <Card Style="height:100%;">
                <CardTabs>
                    <Tabs DefaultActiveKey="1">
                        <TabPane Key="1">
                            <TabTemplate>日志统计</TabTemplate>
                            <ChildContent>
                                <AntDesign.Charts.Column Config="chartConfig" Data="chartData" />
                            </ChildContent>
                        </TabPane>
                    </Tabs>
                </CardTabs>
            </Card>
        </div>
    </GridCol>
    <GridCol Span="10">
        <div style="height:400px;margin-left:10px;">
            <Card Title="常用功能" Style="height:100%;">
                @if (visitMenus != null && visitMenus.Count > 0)
                {
                    foreach (var item in visitMenus)
                    {
                        <div class="ws-func-menu" @onclick="e => Context.Navigate(item)">
                            <Icon Type="@item.Icon" Theme="outline" />
                            <span class="name">@item.Name</span>
                        </div>
                    }
                }
            </Card>
        </div>
    </GridCol>
</GridRow>

<style>
    .ws-space {display:flex;justify-content:space-between;margin:10px 0;background-color:#fff;padding:20px;}
    .ws-welcome {display:flex;padding:10px;}

    .ws-avatar {width:80px;height:80px;}
    .ws-info {padding:10px;}
    .ws-info span {display:block;}
    .ws-name {font-size:1.4rem;}
    .ws-tips {margin-top:10px;color:#888;}

    .ws-func-menu {display:inline-block;width:90px;height:80px;padding:8px;text-align:center;font-size:1rem;cursor:pointer;color:#4188c8;}
    .ws-func-menu:hover {color:#1c66b9;}
    .ws-func-menu .anticon {display:block;font-size:2.2rem;margin:8px auto;}
    .ws-func-menu .name {display:block;width:100%;height:25px;overflow:hidden;}

    .count {display:flex;justify-content:end;list-style:none;}
    .count li {
        width:140px;height:110px;margin:0 10px;
        background-color:#f5f5f5;position:relative;text-align:left;
        -webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;
    }
    .count li .name {display:block;border-bottom:1px solid #e8eaec;padding:5px 10px;}
    .count li .month {
        position:absolute;top:5px;right:5px;font-size:14px;padding:0 5px;
        background-color:#e6f7ff;border:1px solid #91d5ff;color:#1890ff;
        -webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px;
    }
    .count li .amount {
        position:absolute;top:45px;left:5px;right:5px;text-align:center;
        font-size:1.8rem;height:50px;line-height:50px;
    }

    @@media screen and (max-width:768px) {
        .ws-space {justify-content:stretch;}
    }
</style>

@code {
    private UserInfo user;
    private HomeInfo info;
    private object[] chartData;
    private List<Known.MenuItem> visitMenus;
    private ColumnConfig chartConfig = new()
    {
        Name = $"{DateTime.Now:yyyyMM}月系统访问量统计",
        Height = 274,
        Padding = "auto",
        XField = "key",
        YField = "value",
        Meta = new
        {
            Key = new { Alias = "日期" },
            Value = new { Alias = "数量" }
        }
    };

    protected override async Task OnInitPageAsync()
    {
        await base.OnInitPageAsync();

        user = CurrentUser;
        var service = new Services.HomeService { CurrentUser = user };
        info = await service.GetHomeAsync();
        chartData = info?.Statistics?.LogDatas?.FirstOrDefault()?.Series.Select(d => new { d.Key, d.Value }).ToArray();
        visitMenus = Context.GetMenus(info?.VisitMenuIds);
    }
}